function PayRecordAdd_Code(id) { 
	var date=new Date();
	var buffer = new StringBuffer();
	buffer.append('<div id="payrecordid" class="crmsheet border-bottom" val="'+id+'"><div class="ctitle"><div class="cname">回款金额</div><div class="require">*</div></div><div class="ctext"><input id="txt_money" type="text" placeholder="输入回款金额"  value=""/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">付款方式</div><div class="require">*</div></div><div class="ctext"><select id="txt_paytype"><option value="0">现金支付</option><option value="1">支付宝</option><option value="2">微信支付</option><option value="3">财付通</option><option value="4">网银转账</option><option value="5">支票</option><option value="6">邮政汇款</option><option value="7">电汇</option><option value="8">其他</option></select></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">回款期次</div><div class="require">*</div></div><div class="ctext"><select id="txt_period"><option value="1">1期</option><option value="2">2期</option><option value="3">3期</option><option value="4">4期</option><option value="5">5期</option><option value="6">6期</option><option value="7">7期</option><option value="8">8期</option><option value="9">9期</option><option value="10">10期</option><option value="11">11期</option><option value="12">12期</option></select></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div id="headuserid" class="crmsheet border-bottom users" show="1" touserid="'+userid+'"><div class="ctitle"><div class="cname">负 &nbsp;责 &nbsp;人</div><div class="require">*</div></div><div class="ctext"><input id="txt_headuser" type="text" placeholder="" readonly="readonly" value="'+User.RealName+'"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom date"><div class="ctitle"><div class="cname">回款日期</div><div class="require">*</div></div><div class="ctext"><input id="txt_backdate" touserid="" type="text" placeholder="" readonly="readonly" value="'+date.Format("yyyy-MM-dd")+'"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">已开发票</div><div class="require">*</div></div><div class="ctext"><div class="money" style="width:60%"><input id="yes" name="isbill" checked="checked" type="radio" style="width:20px; background:gray;" value="true" /><label for="yes" style="width:35px;">是</label><input id="no" name="isbill" type="radio" style="width:20px; background:gray;" value="false" /><label for="no" style="width:35px;">否</label></div></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom" style="height:120px;"><div class="ctitle"><div class="cname">备注</div></div><textarea id="txt_bak" placeholder="填写订单备注"></textarea></div>');
	return buffer.toString();
};

function Init_PayRecordAdd(){
	var payrecordid=$("#payrecordid").attr("val");
	if(payrecordid!=0)
	{
		var data = {};
		data.act = "One_PayRecord";
		data.id=payrecordid;
		data.source=source;
		data.userid=userid;
		data.comid=comid;
		data.sign=GetSign(data.act);
		mui.getJSON(crm_domain, data, function (json) {
				
	            if (json.state) {
	                payrecord=json.data;
	                $("#txt_money").val(payrecord.Money);
	                $("#txt_paytype").val(payrecord.PayType);
	                $("#txt_period").val(payrecord.Period);
	                $("#txt_headuser").val(payrecord.HeadUserName).attr("touserid",payrecord.HeadUser).parent().parent().attr("touserid",payrecord.HeadUser);
	                $("#txt_backdate").val(payrecord.BackDate.ToDate());
	                $("input[name='isbill'][value='"+(payrecord.IsBill+"").toLowerCase()+"']").prop("checked",true);
	                $("#txt_bak").val(payrecord.Bak);
	            } else {
					plus.nativeUI.toast(json.msg);
	            }
	    });
   }
	mui(".divmsg").on("tap",".users",function(){
			obj10=$(this);
			OpenWindow(4,"选择员工","确定",function(){
					var str1="",str2="",str3="",headimg="";
					touserid="";todepartid="";tocomid="";
	      			var count=0;
	      			mui.each(mui("#userlist input"),function(i,info){
	      				if(info.checked)
	      				{
	      					count++;
	      					touserid += info.value+",";
	      					str1 += info.getAttribute("val")+",";
	      				}
	      			});
	      			obj10.find("input").val(str1.TrimEnd(","));
	      			obj10.find("input").attr("touserid",touserid.TrimEnd(","));
					obj10.attr("touserid",touserid.TrimEnd(","));
	      			CloseWindow();
			});
			
			$("#contentlist4").html(CheckMate_Data());
			data = {};
			data.act = "DepartAndUser_Data";
			data.userid=userid;
			data.comid=comid;
			data.source=source;
			data.sign=GetSign(data.act);
			
			mui.getJSON(admin_domain, data, function(json) {
				Bind_CheckMate(json.data.user,json.data.depart);
				Init_CheckMate();
				
			});
			if($(this).attr("show")=="1")
	      	{
	      		$(".selectbar").hide();
	      	}else
	      	{
				$(".selectbar").show();  				
	      	}
	    });
	    
	mui("#contentlist3").on("tap",".date",function(){
			obj10=this;
			var t=new Date();
			if($(this).find("input").val()!="")
			{
				var year_month_day=$(this).find("input").val().split("-");
				t.setFullYear(year_month_day[0]);
				t.setMonth(year_month_day[1]-1);
				t.setDate(year_month_day[2]);
			}
			plus.nativeUI.pickDate( function(e){
				var d=e.date;
				$(obj10).find("input").val((d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()).ToDate());
			},function(e){
				console.log( "未选择日期："+e.message );
			},{date:t});
		});
	
};




function Save_PayRecord() {
    var data = {};
        data.act = "Save_PayRecord";
        data.userid=userid;
		data.comid=comid;
        data.id = $("#payrecordid").attr("val");
        data.contractid= obj.attr("id");
        data.money = $("#txt_money").val();
        data.paytype = $("#txt_paytype").val();
        data.period = $("#txt_period").val();
        data.headuser = $("#headuserid").attr("touserid");
        data.backdate = $("#txt_backdate").val();
        data.isbill = $("input[name='isbill']:checked").val();
        data.bak = $("#txt_bak").val();
        data.source = source; 
        data.version = version;
        data.sign=GetSign(data.act);
		plus.nativeUI.showWaiting( "正在保存..." );
        
		mui.getJSON(crm_domain, data, function (json) {
			plus.nativeUI.closeWaiting();
			plus.nativeUI.toast(json.msg);
            if (json.state) {
                CloseWindow();
                Init_ContractDetail();
                FindCrmReport();
            } 
        });
};
